package com.lh.principle.inversion.improve.type2;//package com.lh.principle.inversion.improve;

public class Demo2 {
	public static void main(String[] args) {
		ChangHong changHong = new ChangHong();

		// 通过构造器进行依赖传递
		OpenAndClose openAndClose = new OpenAndClose(changHong);
		openAndClose.open();
	}
}

//方式2: 通过构造方法依赖传递
interface IOpenAndClose {
	public void open(); // 抽象方法
}

interface ITV { // ITV接口
	public void play();
}

class OpenAndClose implements IOpenAndClose {
	public ITV tv; // 成员

	public OpenAndClose(ITV tv) { // 构造器
		this.tv = tv;
	}

	public void open() {
		this.tv.play();
	}
}

class ChangHong implements ITV {

	@Override
	public void play() {
		// TODO Auto-generated method stub
		System.out.println("长虹电视机，打开");
	}

}